package main

import (
	"cowb/app/account"
	"cowb/gateway"
	"cowb/log"
	"flag"
	"runtime"
)

func main() {
	log.Debug("cpu num:%d", runtime.NumCPU())
	runtime.GOMAXPROCS(runtime.NumCPU())
	gwHost := flag.String("gwhost", ":8300", "gateway host")
	rpcHost := flag.String("rpchost", ":8301", "rpc service host")
	flag.Parse()
	go func() {
		gateway.Run(*gwHost, *rpcHost)
	}()

	account.Run(":8400")
	/*
		mem.InitRedisPoolDefault("127.0.0.1:6379")
		countChan := make(chan int)
		const max = 5000
		t := time.Now()
		for i := 0; i <= max; i++ {
			go func(id int) {
			back:
				_, err := redis.Strings(mem.Do("hmget", "user:1", "name", "lv", "viplv"))
				if err == redis.ErrPoolExhausted {
					goto back
				} else if err != nil {
					//log.Error("%v", err)
					countChan <- -id
				} else {
					countChan <- id
				}
				//fmt.Println(ret)
			}(i)
		}

		oks := 0
		faileds := 0
		for {
			select {
			case ret := <-countChan:
				if ret < 0 {
					faileds++
					//log.Debug("failed id:%d", ret)
				} else {
					oks++
					//log.Debug("ok id:%d", ret)
				}
				if oks+faileds >= max {
					log.Debug("ok:%d,failed:%d", oks, faileds)
					log.Debug("use:%v", time.Now().Sub(t))
					return
				}
				break
			}
		}
	*/
}
